

***Note: replicators should set directory to open data 
*cd ""

*Also note data are in .sav format, need to be put in stata

********** FIGURE 2g: Gender Attitudes, Africa **********

*Based on Afrobarometer 2018, see appendix. Original dataset: https://www.afrobarometer.org/data

clear all
use Afrobarometer.dta

 label var D "Discrimination"
 label var PD "Perceptions of discrimination"

 rename country Country
 
decode Country, gen(country) 

gen North=0
replace  North=1 if country=="Algeria" | country=="Egypt" | country=="Libya" | country=="Morocco" | country=="Sudan" | country=="Tunisia" | country=="Western Sahara"

gen West=0
replace West=1 if country=="Benin" | country=="Burkina Faso" | country=="Cape Verde" | country=="Côte d'Ivoire" | country=="Gambia" | country=="Ghana" | country=="Guinea" | country=="Guinea-Bissau" | country=="Liberia" | country=="Mali" | country=="Mauritania" | country=="Niger" | country=="Nigeria" | country=="Senegal" | country=="Sierra Leone" | country=="Togo" | country=="São Tomé and Príncipe"

gen East=0
replace East=1 if country=="Burundi" | country=="Comoros" | country=="Djibouti" | country=="Eritrea" | country=="Ethiopia" | country=="Kenya" | country=="Madagascar" | country=="Malawi" | country=="Mauritius" | country=="Mozambique" | country=="Rwanda" | country=="Seychelles" | country=="Somalia" | country=="South Sudan" | country=="Tanzania"

gen Central=0
replace Central=1 if country=="Angola" | country=="Cameroon" | country=="Central African Republic" | country=="Chad" | country=="Democratic Republic of the Congo" | country=="Republic of the Congo" | country=="Equatorial Guinea" | country=="Gabon" | country=="São Tomé and Príncipe"


gen South=0
replace South=1 if country=="Botswana" | country=="Eswatini" | country=="Lesotho" | country=="Namibia" | country=="South Africa"



gen Area=.
replace Area=1 if North==1
replace Area=2 if East==1
replace Area=3 if West==1
replace Area=4 if Central==1
replace Area=5 if South==1


label variable Area "Continent"
la def aria  1 "North" 2 "East"  3 "West" 4 "Central" 5 "South", modify
la val Area aria

   grstyle init
 grstyle set legend 2,  nobox
 grstyle set size 8pt: tick_label key_label
 grstyle set size 12pt: heading
 grstyle set size 10pt: subheading axis_title 
 grstyle set graphsize 13cm 11.5cm
 

reg    PD D
ereturn list
loc N6= e(N)
local b= round(_b[D],.001)
local t = _b[D]/_se[D]
local p =round(2*ttail(e(df_r),abs(`t')),.001)


  graph twoway    (lfitci PD  D,   lcol(black)  lwidth(medthick) ciplot(rline) blpattern(dash) acolor(black%65) )     (scatter PD  D if Area==1,       mcolor(black)   msymbol(d))   (scatter PD  D if Area==2,   mcolor(black)    msymbol(S)) (scatter PD  D if Area==3,   mcolor(black)      msymbol(o)) (scatter PD  D if Area==4,   mcolor(black)    msymbol(T)) (scatter PD  D if Area==5,   mcolor(black)    msymbol(X)), name(a, replace)    legend(position(12) rows(1)  order(3 "North" 4 "East" 5 "West" 6 "Central" 7 "South") span) ytitle("Perceptions of discrimination")    xtitle("Discriminatory attitudes") note("Author's computation based on the Afrobarometer." "Plot country-round pairwise correlation. {&rho} = `b' | {it:p-value} = `p' | {it:N} = `N6'." ,size(vsmall) span) subtitle("{bf: Gender attitudes in Africa}") 
  graph export "Graph/Figure2g.tif", replace 
  graph save "Graph/Figure2g", replace
